package com.sphd.Restaurant.presenter;

import android.widget.Toast;

import com.android.volley.VolleyError;
import com.sphd.Restaurant.base.MyApplication;
import com.sphd.Restaurant.infos.LoginInfo;
import com.sphd.Restaurant.interfFace.VolleyCallBack;
import com.sphd.Restaurant.utils.JsonUtil;
import com.sphd.Restaurant.utils.VolleyErrorHelper;
import com.sphd.Restaurant.views.MyDataView;


import java.util.List;

/**
 * Created by Hu on 2016/10/17.
 */

public class MyDataP extends BasePresenter implements VolleyCallBack<String> {
    MyDataView myDataView;

    public MyDataP(MyDataView myDataView) {
        this.myDataView = myDataView;
    }

    @Override
    public void addData(String url) {
        myDataView.showdialog();
        sendStringUrl(url,this);
    }

    @Override
    public void onResponse(String jsos) {
        List<LoginInfo> loginInfos = JsonUtil.getListFromString(jsos,LoginInfo.class);
        myDataView.sendResInfo(loginInfos.get(0));
        myDataView.dissmissdialog();
    }

    @Override
    public void onErrorResponse(VolleyError error) {
        myDataView.dissmissdialog();
        Toast.makeText(MyApplication.getContext(), VolleyErrorHelper.getMessage(error),Toast.LENGTH_SHORT).show();
    }
}
